package gek.uni.aspirant.ocl.parser.mptree.tree.utils;

import java.util.HashMap;
import java.util.Map;

public class VariableNameManager {

  private Map<String, Integer> name2VarName = new HashMap<String, Integer>();

  private static VariableNameManager instance = new VariableNameManager();

  private VariableNameManager() {

  }
  
  public static VariableNameManager getInstance(){
    return instance;
  }

  public String getUniqueVarNameForOperation(String operationName) {
    Integer cnt = name2VarName.get(operationName);
    if (cnt == null)
      cnt = 0;
    else
      cnt++;
    name2VarName.put(operationName, cnt);

    StringBuilder bldr = new StringBuilder(OfflineUtils
        .createPrologVariableName(operationName));
    bldr.append("_").append(String.valueOf(cnt));
    return bldr.toString();
  }

}
